package com.example.service.impl;

import com.example.service.MsgService;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.concurrent.locks.ReentrantLock;

import static com.sun.xml.internal.ws.spi.db.BindingContextFactory.LOGGER;

@Service("msgServuce")
public class MsgServiceImpl implements MsgService {

    @Qualifier("createProducerConfig")
    @Autowired
    DefaultMQProducer producer;
  ReentrantLock lock = new ReentrantLock();
    @Override
    public void orderMsgSend(Integer showNum, String topic) {
        String msg = "消息共计销售" + showNum + "件";
        Message sendMsg = new Message("DemoTopic","DemoTag",msg.getBytes());
        //默认3秒超时
        SendResult sendResult = null;
        try {
            sendResult = producer.send(sendMsg);
        } catch (Exception e) {
            e.printStackTrace();
        }
        LOGGER.info("消息发送响应信息："+sendResult.toString());


    }
}
